package admin

import (
	"chaowan/data_source"
	"chaowan/models"
	"github.com/gin-gonic/gin"
	"net/http"
)

func Configs(ctx *gin.Context) {

	var users []models.Config
	data_source.Db.Find(&users)
	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    users,
		"msg":     "ok",
	})
	return
}

type ConfigBody struct {
	ID    int64  `json:"id" gorm:"id"`
	Name  string `json:"name" gorm:"name"`
	Value string `json:"value" gorm:"value"`
}

func Configupdate(ctx *gin.Context) {
	request := ConfigBody{}
	ctx.ShouldBind(&request)
	id := request.ID
	//name := request.Name
	value := request.Value
	gt := models.Config{
		//Name:  name,
		Value: value,
	}
	data_source.Db.Where("id = ?", id).Updates(&gt)
	ctx.JSON(http.StatusOK, gin.H{
		"code":    0,
		"error":   0,
		"success": 200,
		"data":    "ok",
		"msg":     "ok",
	})
	return
}
